package com.sophialex.health.record.action;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.action.Action;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;

import com.sophialex.health.common.platform.SuperContext;
import com.sophialex.health.person.vo.HrPerson;
import com.sophialex.health.record.Messages;
import com.sophialex.health.record.common.Constants;
import com.sophialex.health.record.common.util.DataSource;
import com.sophialex.health.record.common.util.EventType;
import com.sophialex.health.record.common.util.HealthRecordListenerRegister;
import com.sophialex.health.record.common.utils.ImageUtil;
import com.sophialex.health.record.perspective.PersonRecordPerspective;
import com.sophialex.health.system.frame.dialog.DialogManager;
import com.sophialex.health.system.frame.util.ViewUitl;
import com.sophialex.health.system.lktable.LKTable;
/**
 * 打开健康档案
 * <p>Title:Health</p>
 * <p>OperRecordAction</p>
 * 
 * Alex Apr 24, 2011 12:10:46 PM create
 * @author <a href='wanghao924@126.com'>Alex</a>
 * QQ: 873987060;
 * @version 1.0
 */
public class OpenRecordAction extends Action implements IWorkbenchAction {
    public static final String ID = "com.sophialex.health.record.action.OperRecordAction";
    
    private IWorkbenchWindow workbenchWindow;
    
    private LKTable showTable;

	public OpenRecordAction(IWorkbenchWindow workbenchWindow,LKTable showTable){
    	if(workbenchWindow==null){
    		throw new IllegalArgumentException();
    	}
    	this.showTable = showTable;
    	this.workbenchWindow = workbenchWindow;
    	setId(ID);
    	setText(Messages.getString("CancelFamilyRelationAction.5"));
    	setImageDescriptor(ImageUtil.open);
    }
    
	public void dispose() {
		workbenchWindow = null;
	}
	
	public void run(){
		if(workbenchWindow == null){
			return;
		}
		HrPerson currentPerson = SuperContext.currentPerson;
		if(currentPerson == null){
			DialogManager.invokeWarnDlg(Messages.getString("Common.12"));
			return;
		}
		if (showTable.getSelection() != null) {
			HrPerson hrPerson = (HrPerson) showTable.getSelection();
			SuperContext.currentPerson = hrPerson;
			HealthRecordListenerRegister.getInstance().postEvent(hrPerson,EventType.REFRESH);
			ViewUitl.openPersperctive(PersonRecordPerspective.ID);		
		}else{
			DialogManager.invokeInfoDlg(Messages.getString("CancelFamilyRelationAction.6"));
			
		}
	
	}

}
